<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/12 0012
 * Time: 上午 10:05
 */

namespace App\Http\Classes;


abstract class Compress
{
    private $file;
    public $dst;
    public $height;
    public $width;
    public $code;
    public $msg;
    public $url;
    public $host;
    private $name;

    public function __construct($name,$file)
    {
        $this -> file = $file;
        $this -> setName($name);
        $this -> setHost();
        $this -> setDst();
        $this -> setSize();
        $this -> compress();
    }

    public abstract function setDst();

    public abstract function setSize();

    private function setName($name){
        $this -> name = $name;
    }

    private function setHost(){
        $this -> host = 'http://'.$_SERVER['HTTP_HOST'].'/';
    }

    private function compress(){
        $file = $this -> file;
        list($width, $height) = getimagesize($file);
        $newwidth = $this -> width;
        $newheight = $this -> height;
        $src_im = imagecreatefromjpeg($file);
        $dst_im = imagecreatetruecolor($newwidth, $newheight);
        imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
        //imagejpeg($dst_im);
        if(imagepng($dst_im, $this -> dst)){

        }
        imagedestroy($dst_im);
        imagedestroy($src_im);
    }

    public abstract function getResult();
}